The invention relates to a moving-picture encoding apparatus for encoding a moving picture in block units.
Conventionally, the encoding of a moving picture employs a block encoding method. In block encoding, three encoding methods are used adaptively, namely (1) encoding of interframe difference, (2) motion-compensated encoding of interframe difference and (3) intraframe encoding.
These three methods of encoding are described below.
(1) Encoding of Interframe Difference
This is an encoding method of obtaining the difference between a block to be encoded and a block at the same position in the previous frame and then encoding the difference. With the method of encoding interframe difference, the difference becomes closer to zero the higher the correlation between frames. Encoding is more efficient as a result. The block of difference data is subjected to a discrete cosine transformation, the transform coefficient data obtained is quantized and Huffman codes are subsequently assigned. When all of the data becomes zero after quantization, this means that the quantized image is the same as that of the same block in the previous frame. Accordingly, there is no transmission of code.
(2) Method of Motion-compensated Encoding Interframe Difference
This method involves matching the block to be encoded and neighboring blocks centered on the block at the same position in the previous frame, selecting the block that is most similar and obtaining the difference between the blocks. The difference data is subjected to a discrete cosine transformation and subsequently quantized. Huffman codes are then assigned.
(3) Method of Intraframe Encoding
In a case where the correlation between frames is small, the dynamic range is widened and the amount of information is increased rather than decreased by taking the difference between the frames. In this case, therefore, intraframe encoding is carried out. In intraframe encoding, the discrete cosine transformation is applied to the original image directly, followed by quantization and encoding.
A method of deciding which of these three conventional encoding methods to use is described with reference to FIG. 6, which is a flowchart of the deciding processing.
In FIG. 6, it is determined at step S21 whether an output-code buffer (not shown) has overflowed. If the decision rendered is YES, the program proceeds to step S24 and the method of coding interframe difference is used. If a NO decision is rendered at step S21, the program proceeds to step S22, where it is decided whether to perform motion compensation. As shown in FIG. 7, the decision is made using the average of the absolute-value differences between blocks when motion compensation is performed and the average of the absolute-value differences between blocks when motion compensation is not performed. If the result of the decision at step S22 is YES (motion compensation ON), the program proceeds to step S25 and the method of motion-compensated encoding of interframe difference is used.
If the result of the decision at step S22 is NO (motion compensation OFF), the program proceeds to step S23, where a decision is made to use encoding of interframe difference or intraframe encoding. As shown in FIG. 8, the decision of step S22 is performed using variance values of intraframe data and a geometrical average of interframe difference. Intraframe encoding is performed at step S26 or encoding of intraframe difference at step S27, depending upon the decision rendered at step S23.
In the above-described decision processing, the statistics of a 16xc3x9716 pixel block of luminance data are used. Furthermore, in the encoding described below, the unit of processing is 8xc3x978 pixels. As for the breakdown, the 16xc3x9716 pixel block is partitioned into four blocks of 8xc3x978 pixels, and there is a total of six 8xc3x978 pixel blocks of the four 8xc3x978 pixel blocks and two 8xc3x978 pixel blocks of color difference data describing a position that is spatially the same as the four 8xc3x978 pixel blocks. Encoding processing of the same mode is applied to the six 8xc3x978 pixel blocks.
Control of the amount of code generated is described below.
Control for making the amount of generated encoded data conform to the transmission rate is required. This is carried out by the following method: The generated code is fed into a buffer whose code capacity is equivalent to one frame. The code is sequentially transmitted from the buffer at a speed commensurate with the transmission rate. The encoder monitors the sufficiency of the code in the buffer and suppresses the generation of code by enlarging the quantization step when the amount of code that has been generated is excessive. Conversely, the encoder generates more code by reducing the quantization step when the rate at which code is generated falls below the transmission rate. When the buffer overflows, the encoder makes the quantization step very large and halts the generation of code. By virtue of this operation, a fixed amount of code is generated per unit time.
The operation of the encoder is described with reference to FIG. 9. Block data that has entered from a connector 301 is transmitted on lines 302 and 303. Meanwhile, an overflow signal from the output-code buffer (not shown) enters from a connector 304 and is transmitted on lines 305 and 306. A mode decision unit 37 decides the processing mode in accordance with the above-described method upon referring to the block data on line 303 and a previous-frame memory 38. When it has been decided that the method of encoding interframe difference is appropriate, the mode decision unit 37 reads data of a block at a position identical with that of the input block out of the previous-frame memory 38 via line 307 and outputs the data on the signal line 308. When it has been decided that the method of motion-compensating encoding of interframe difference is appropriate, the mode decision unit 37 reads the best matching block data out of the previous-frame memory 38 via line 307 and outputs the data on the signal line 308. When it has been decided that the intraframe encoding method is appropriate, the mode decision unit 37 produces zero data and outputs the data on the line 308. At the same time, the mode decision unit 37 outputs, on a line 312, vector data representing the relative position of the best matching block, which has been obtained by motion compensation, and the encoded block. The block data on the line 308 is transmitted on lines 309 and 310.
The difference between the block data from the line 310 and the input block data from the line 302 is determined and provided to a masking unit 32 via a DCT (direct cosine transform) circuit 31. When the signal from the connector 304 indicates an overflow state, the mode decision unit 37 selects interframe-difference encoding unconditionally and the masking unit 32 masks all of the difference data to zero. The DCT coefficient data from the masking unit 32 is quantized by a quantizer 33 and the quantized data is provided to an encoder 34 and a reverse quantizer 35. In response to a selection-mode signal from line 311, the encoder 34 assigns a Huffman code to the quantized DCT coefficient data and outputs the result on a line 313. By means of reverse quantization, the reverse quantizer 35 reproduces frequency data identical with that provided to an external decoder, not shown. The reproduced frequency data is again transformed into a difference signal by a reverse-DCT circuit 36, and this difference signal is added to the signal from the line 309, thereby reproducing an image identical with that transmitted. This image is again stored in the previous-frame memory 38.
With the example of the prior art described above, intraframe encoding is performed in a case where the predicted error is very large. Interframe encoding is performed in other cases.
Consider a case in which the 16xc3x9716 pixel block of luminance data is almost entirely flat, the two 8xc3x978 pixel blocks of color-difference data are also flat, the image of the previous frame is large and is an image having an AC component. Such a condition tends to occur when a transition is made from a complicated image to a flat, even image owing to a scene change.
When the conventional encoding methods are used under these circumstances, it is found that interframe encoding is unsuitable because the power of the difference between images is too large. Though intraframe encoding can be used, a large amount of code is produced with this method. In either case, a problem arises that a great deal of code is produced when encoding an image having little redundancy.
Accordingly, an object of the present invention is to provide a moving-picture encoding apparatus capable of performing more efficient encoding.
According to the present invention, the foregoing object is attained by providing a moving-picture encoding apparatus for performing encoding in block units, comprising:
selecting means for selecting prescribed encoding on the basis of a decoded block of a frame which includes a block to be encoded; and
encoding means for performing predictive encoding of the block to be encoded by using the encoding selected by the selecting means.
In accordance with this arrangement, the decoded image portion of a frame currently undergoing encoding is used without obtaining a predicted image only in past frames. This makes it possible to perform encoding more efficiently.
Other features and advantages of the present invention are apparent from the following description taken in conjunction with the accompanying drawings, in which like reference characters designate the same or similar parts throughout the figures thereof.